package top.meeting.room.module.book.corn;

import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.SqlPara;
import com.xiaoleilu.hutool.date.DateUtil;
import net.dreamlu.event.EventKit;
import top.meeting.room.module.book.event.ApproveEvent;
import top.meeting.room.module.book.event.BookMeetEvent;
import top.meeting.room.module.book.model.Book;

import java.util.Date;
import java.util.List;

/**
 * Created by Lyt on 2017/10/17.
 */
public class InformApprove implements Runnable {
    @Override
    public void run() {
        System.out.println("InformApprove");
        Date now = new Date();
        String today = DateUtil.format(now, "yyyy-MM-dd");
        Long bookDate = DateUtil.parseDate(today).getTime();
        SqlPara sqlPara = Book.dao.getSqlPara(Book.book_pageModel, Kv.by("bookDate", bookDate).set("status", 0));
        sqlPara.setSql(sqlPara.getSql().replaceFirst(" AND ", " WHERE "));
        List<Book> books = Book.dao.find(sqlPara);
        if (books.size() != 0) {
            //提醒审批者审批
            EventKit.post(new BookMeetEvent("", "尚有预订未审批，请尽快审批!!!"));
        }
    }
}
